package com.durl.simple;

import java.net.URL;

import org.nutz.dao.Dao;
import org.nutz.dao.DatabaseMeta;
import org.nutz.dao.SqlManager;
import org.nutz.dao.impl.FileSqlManager;
import org.nutz.lang.Lang;

import com.durl.core.UrlHouse;
import com.durl.simple.house.MysqlIniter;
import com.durl.simple.house.PostgresqlIniter;

public class DBUrlHouse implements UrlHouse {

	private Dao dao;

	public DBUrlHouse(Dao dao) {
		this.dao = dao;
	}

	@Override
	public void initURLHouse() {
		DatabaseMeta dm = dao.meta();
		SqlManager sm = new FileSqlManager("sqls/UrlHouse.sqls");
		URLHouseIniter urlIniter = null;
		if (dm.isPostgresql()) {
			urlIniter = new PostgresqlIniter(dao, sm);
		} else if (dm.isMySql()) {
			urlIniter = new MysqlIniter(dao, sm);
		} else {
			throw Lang.makeThrow("Do not support this kind of DB.");
		}
		urlIniter.initTable();
		
		
	}

	@Override
	public URL getOriginURL(URL shortUrl) {
		UrlWeaver urlWeaver = new UrlWeaver();

		return null;
	}

	@Override
	public boolean saveShortURL(URL originUrl, URL shortUrl) {
		return false;
	}

}
